package com.zxmc.server.controller.admin;


import com.zxmc.common.result.Result;
import com.zxmc.pojo.dto.NovelQueryDto;
import com.zxmc.pojo.entity.Novel;
import com.zxmc.server.service.NovelService;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.apache.catalina.util.Introspection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController("adminNovelController")
@RequestMapping("/admin/novel")
@Slf4j
@Api(tags = "小说相关接口")
public class NovelController {
    @Autowired
    private NovelService novelService;
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除小说")
    public Result delete(@PathVariable Integer id) {
        log.info("删除小说：{}", id);
        novelService.delete(id);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查询小说数据(条件查询)")
    public Result<List<Novel>> list(NovelQueryDto novelQueryDto) {
        log.info("查询小说数据{}", novelQueryDto);
        List<Novel> novels= novelService.list(novelQueryDto);
        return Result.success(novels);
    }

    @GetMapping("/update/{id}")
    @ApiOperation("更新小说")
    public Result update(@PathVariable Integer id) {
        log.info("更新小说：{}", id);
        novelService.crawlerById(id);
        return Result.success();
    }

    @GetMapping("/insert")
    @ApiOperation("插入小说")
    public Result insert(@RequestParam String url) {
        log.info("插入小说：{}", url);
        novelService.crawlerByUrl(url);
        return Result.success();
    }
}
